<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <title>vue</title>
</head>

<body>

  <div id="app">
    <p>{{msg}}</p>

    <p v-for="(value, name, index) in object">
      {{value}}--{{name}}--{{index}}
    </p>

    <p v-for='n in evenNumbers'>{{ n }}</p>
    <hr>
    <button @click="add">+</button>
    <p>{{count}}</p>
    <hr>
    <button-counter></button-counter>
    <button-counter></button-counter>
    <button-counter></button-counter>

    <hr>

    <blog-post title="My journey with Vue"></blog-post>

    <my-com title="news"></my-com>

    <hr>

    <div :style="{ fontSize: postFontSize + 'em' }">
      <blog-post2 v-for="post in posts" v-bind:key="post.id" v-bind:post="post"
      v-on:enlarge-text="postFontSize += 0.1">
      </blog-post2>
    </div>
  </div>


  <script src="https://cdn.bootcdn.net/ajax/libs/vue/2.6.14/vue.common.dev.js"></script>


  <script>
    Vue.component('button-counter', {
      data: function () {
        return {
          count: 0
        }
      },
      template: '<button v-on:click="count++">You clicked me {{ count }} times.</button>'
    })


    Vue.component('blog-post', {
      props: ['title'],
      template: '<h3>{{ title }}</h3>'
    })

    Vue.component('my-com', {
      props: ['title'],
      template: '<h2>{{ title }}</h2>'
    })

    //监听子组件事件
    Vue.component('blog-post2', {
      props: ['post'],
      template: `
        <div class="blog-post">
          <h3>{{ post.title }}</h3>
          <button>
            Enlarge text
          </button>
          <div v-html="post.content"></div>
        </div>
      `
    })


    const app = new Vue({
      el: '#app',
      data: {
        msg: 'some msg',
        object: {
          title: 'How to do lists in Vue',
          author: 'Jane Doe',
          publishedAt: '2021-08-02'
        },
        numbers: [1, 2, 3, 4, 5],
        count: 0,
        postFontSize: 1,
      },
      computed: {
        evenNumbers: function () {
          return this.numbers.filter(function (number) {
            return number % 2 === 0
          })
        }
      },
      methods: {
        add() {
          this.count++;
        }
      }
    })
  </script>

</body>

</html>